package com.glenet.salary.action;

import java.util.List;

import com.glenet.salary.dao.HrAgreementDao;
import com.glenet.salary.dao.HrCompanyDao;
import com.glenet.salary.dao.HrSubTemplateDao;
import com.glenet.salary.entities.HrAgreement;
import com.glenet.salary.entities.HrCompany;
import com.glenet.salary.entities.HrMap;
import com.glenet.salary.entities.HrSubTemplate;

/**
 * @author MeiWenhui
 * 
 */
@SuppressWarnings("serial")
public class HrAgreementAction extends BaseAction {

	private HrAgreementDao agreementDao = new HrAgreementDao();
	private HrAgreement agreement;
	private HrCompanyDao companyDao = new HrCompanyDao();
	private HrSubTemplateDao subTemplateDao = new HrSubTemplateDao();

	private Long id;

	public String add() throws Exception {
		initMap();
		return SUCCESS;
	}

	private void initMap() {
		List<HrMap> agreement_category = this.getMaps("AK");
		req.setAttribute("agreement_category", agreement_category);
		List<HrMap> agreement_state = this.getMaps("AJ");
		req.setAttribute("agreement_state", agreement_state);
		List<HrMap> banks = this.getMaps("AH");
		req.setAttribute("banks", banks);
		
		List<HrMap> unionPay = this.getMaps("AA");
		req.setAttribute("unionPay", unionPay);
		List<HrMap> serverPay = this.getMaps("AB");
		req.setAttribute("serverPay", serverPay);

		List<HrCompany> companys = companyDao.getCompany(0, Integer.MAX_VALUE);
		req.setAttribute("companys", companys);
		
		List<HrSubTemplate> tpl = subTemplateDao.list(0, Integer.MAX_VALUE);
		req.setAttribute("tpl", tpl);
	}

	public String save() throws Exception {
		System.out.println(agreementDao.save(agreement));
		return SUCCESS;
	}

	public String edit() throws Exception {
		initMap();
		agreement = agreementDao.getAgreement(id);
		return SUCCESS;
	}

	public String get() throws Exception {
		initMap();
		agreement = agreementDao.getAgreement(id);
		return SUCCESS;
	}

	public String update() throws Exception {
		boolean flag = agreementDao.update(agreement);
		return SUCCESS;
	}

	public String list() throws Exception {
		List<HrAgreement> agres = agreementDao.getAgreement(offset, limit);
		System.out.println(agres.size());
		req.setAttribute("agres", agres);
		return SUCCESS;
	}

	public String delete() throws Exception {
		boolean flag = agreementDao.delete(id);
		return SUCCESS;
	}

	public HrAgreement getAgreement() {
		return agreement;
	}

	public void setAgreement(HrAgreement agreement) {
		this.agreement = agreement;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}
